<div class="container-fluid">
    <div class="wrapper">
        <div class="panel" id="nav">
            <div class="panel-heading"><h3 class="panel-title">Shipmentid采购单信息补录</h3></div>
            <div class="panel-body">

                <form action="" method="get" class="form" onsubmit="return submitCheck()">
                    <div class="container-fluid">
                        <!--<div class="col-sm-12 col-md-3  add-space">-->
                            <!--<div class="input-group input-group-md">-->
                                <!--<span class="input-group-addon">shipmentid</span>-->
                                <!--<input type="text" name="shipmentid" class="form-control" value="{$_GET['shipmentid']}">-->
                            <!--</div>-->
                        <!--</div>-->
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">SKU</span>
                                <input type="text" name="sku" class="form-control" value="{$_GET['sku']}">
                            </div>
                        </div>
                        <div class="col-md-2 add-space">
                            <input class="btn btn-primary" type="submit" value="查询">
                            <!--<input class="btn btn-primary" type="reset" value="重置">-->
                        </div>
                    </div>
                </form>
                <div class="clearfix"></div>
                <hr>

                <form action="__URL__/shipmentIdSingleSave" method="post" >
                <table class="table table-striped  table-hover" cellspacing="0" width="100%" id="table">
                    <thead>
                    <tr>
                        <th width="20" style="vertical-align: middle;text-align: center">序号</th>
                        <!--<th style="vertical-align: middle;text-align: center">shipmentId</th>-->
                        <!--<th style="vertical-align: middle;text-align: center">sellerSku</th>-->
                        <th style="vertical-align: middle;text-align: center">sku</th>
                        <!--<th style="vertical-align: middle;text-align: center">个数</th>-->
                        <th style="vertical-align: middle;text-align: center">采购单信息</th>
                        <th style="vertical-align: middle;text-align: center">操作</th>
                    </tr>
                    </thead>
                    <tbody id="StockIn"  >
                    <volist name="data" id="da" key="num">
                        <tr >
                            <td style="vertical-align: middle;text-align: center">{$num}</td>
                            <!--<td style="vertical-align: middle;text-align: center">{$da.shipmentid}</td>-->
                            <!--<td style="vertical-align: middle;text-align: center">{$da.seller_sku}</td>-->
                            <td style="vertical-align: middle;text-align: center">{$da.sku}</td>
                            <!--<td style="vertical-align: middle;text-align: center">{$da.quantity}</td>-->
                            <td class="text-left" >
                                <table style="width: 100%">
                                    <tbody>
                                    <tr>
                                        <td>入库单号</td>
                                        <td>实际入库数量</td>
                                        <td>入库可用数量</td>
                                        <td>主体</td>
                                        <td>出口退税</td>
                                        <td>采购单号</td>
                                        <td>含税单价</td>
                                        <!--<td>供应商</td>--><!--onblur="findPu($(this))"-->
                                    </tr>
                                    <volist name="da.purchaseOrder" id="pu" key="n">
                                        <tr>
                                            <td><input type="hidden" name="{$da.sku}[{$n}][warehouseorders_id]" value="{$pu.warehouseorders_id}">{$pu.warehouseorders_id}</td>
                                            <td><input type="hidden" name="{$da.sku}[{$n}][fromWareQty]" value="{$pu.fromWareQty}">{$pu.fromWareQty}</td>
                                            <td>{$pu.available_quantity}</td>
                                            <td class="enterprise_dominant"><input type="hidden" name="{$da.sku}[{$n}][enterprise_dominant]" value="{$pu.enterprise_dominant}">{$pu.enterprise_dominant_name}</td>
                                            <td><input type="hidden" name="{$da.sku}[{$n}][export_tax_rebate]" value="{$pu.export_tax_rebate}">{$pu.export_tax_rebate_name}</td>
                                            <td class="puId"><input type="text" name="{$da.sku}[{$n}][puId]"  value="{$pu.puId}" onblur="findPu($(this))" required class="w120 form-control"></td>
                                            <td class="price"><input type="text" name="{$da.sku}[{$n}][exportSinglePrice]" value="{$pu.exportSinglePrice}" readonly class="w80 form-control"></td>
                                            <td class="suId" disabled><input type="hidden" name="{$da.sku}[{$n}][supplier_id]" value="" readonly class="w80 form-control"></td>
                                        </tr>
                                    </volist>

                                    </tbody>
                                </table>
                            </td>
                            <td style="vertical-align: middle;text-align: center">
                                <button type="submit"  class="btn  btn-success" disabled id="save">保存</button>
                                <!--<button type="button" onclick="delate_remove(this)" class="btn  btn-success add-space">删除-->
                                </button>
                            </td>
                        </tr>
                    </volist>

                </table>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="__PUBLIC__/javascripts/admin/layer/layer.js"></script>
<script>
    function submitCheck() {
        if($.trim($("input[name='sku']").val())==''){
            layer.msg('请填写sku',{icon: 5});
            return false;
        }else{
            return true;
        }
    }
    function findPu(obj) {
        var sku = $.trim($("input[name='sku']").val());
        var dominant = obj.parent('td').siblings('.enterprise_dominant').children().val();
//        alert(dominant);
        $('#save').attr("disabled", true);
        $.ajax({
            type: "post",
            async: true,
            url: "{:U('Inboundshipmentplan/checkPurchaseOrderId')}",
            data: {'purchaseorder_id':obj.val(),'sku':sku,'enterprise_dominant':dominant},
            dataType: "json",
            success: function(data){
                if(data.status==200){
//                    layer.msg('检验成功', {icon: 6});
                    obj.parent('td').next('.price').children().val(data.data['export_single_price']);
                    obj.parent('td').nextAll('.suId').children().val(data.data['supplier_id']);
                    $('#save').attr("disabled", false);
                } else {
                    obj.val('');
                    obj.parent('td').next('.price').children().val('');
                    obj.parent('td').nextAll('.suId').children().val('');
                    layer.msg(data.data, {icon: 5});
                }

            }
        });
    }

</script>